package com.bw.a2207a.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.bw.a2207a.base.BaseBean
import com.bw.a2207a.base.BaseViewModel
import com.bw.a2207a.bean.LoginBean
import com.bw.a2207a.http.HttpUtil
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

/**
 *
 * @ClassName: RegisterViewModel
 * @Description: java类作用描述
 * @Author: zhangyanchao
 * @CreateDate: 2024/10/16 12:21 PM
 * @Version: 1.0
 */
class RegisterViewModel : BaseViewModel() {
    val registerLiveData = MutableLiveData<BaseBean<LoginBean>>()

    /**
     * 实现注册功能
     * @param map HashMap<String, String>
     */
    fun register(map: HashMap<String, String>) {
        //通过viewModelScope，开启协程，发送网络请求
        viewModelScope.launch {
            withContext(Dispatchers.IO) {
                registerLiveData.postValue(apiService.register(map))
            }
        }
    }


}